<?php

App::uses('AppModel', 'Model');

class Kalkulator extends AppModel {

    public $useTable = false;
    
    public $validate = array(
        'zapremina' => array(
            array(
                'rule'    => 'notEmpty',
                'message' => 'Morate uneti zapreminu motora.'
            ),
            array(
                'rule'    => 'numeric',
                'message' => 'Zapremina motora mora biti broj. npr: 1998'
            )
        )
    );

    public function calculate($data) {
        $invoice = array();
        $items   = array(
            'komunalna'   => 'KalkulatorKomunalna',
            'porez'       => 'KalkulatorPorez',
            'osiguranje'  => 'KalkulatorOsiguranje',
            'nalepnica'   => 'KalkulatorNalepnica',
            'saobracajna' => 'KalkulatorSaobracajna',
            'tablice'     => 'KalkulatorTablice'
        );
        
        foreach ($items as $key => $modelName) {
            App::uses($modelName, 'Model');
            $Model = new $modelName;
            $invoice[$key] = $Model->calculate($data);
        }
        
        return $invoice;
    }
}